DEFINE VARIABLE base_curr  AS CHARACTER.
DEFINE VARIABLE s_date AS DATE.
DEFINE VARIABLE e_date AS DATE.
DEFINE VARIABLE part   AS CHARACTER.
DEFINE VARIABLE vend   AS CHARACTER.

DEFINE TEMP-TABLE exc 
    FIELD exc_curr LIKE exr_curr1
    FIELD exc_rate LIKE exr_rate  
    INDEX exc_index IS PRIMARY exc_curr ASCENDING .

ASSIGN base_curr = "RMB".
ASSIGN s_date = 04/01/04.
ASSIGN e_date = 04/30/04.
ASSIGN part = "151-5027".
ASSIGN vend = ?.

/*create the exchange rate of currency */
CREATE exc.
ASSIGN exc_curr = base_curr
       exc_rate = 1.0.

FOR EACH cu_mstr WHERE cu_curr <> base_curr NO-LOCK:
    FOR EACH exr_rate WHERE exr_start_date <= e_date AND e_date <= exr_end_date NO-LOCK:

        IF exr_curr1 = base_curr AND exr_curr2 = cu_curr THEN DO:
           FIND FIRST exc WHERE exc_curr = cu_curr NO-ERROR.
           IF NOT AVAILABLE exc THEN DO:
              CREATE exc.
              ASSIGN exc_curr = exr_curr2
                     exc_rate = exr_rate.
           END.
        END.

        IF exr_curr2 = base_curr AND exr_curr1 = cu_curr THEN DO:
           FIND FIRST exc WHERE exc_curr = cu_curr NO-ERROR.
           IF NOT AVAILABLE exc THEN DO:
              CREATE exc.
              ASSIGN exc_curr = exr_curr1
                     exc_rate = exr_rate2.
           END.
        END.

    END.
END.

FOR EACH pc_mstr WHERE (pc_part BEGINS part OR part = ?)
                   AND (pc_list = vend OR vend = ?) AND pc_list <> "S15032"
                   AND ((pc_start <= s_date AND (pc_expire >= e_date OR pc_expire = ?)) 
                         OR ((s_date <= pc_start AND pc_start <= e_date) AND pc_expire >= e_date)
                         OR (s_date <= pc_expire AND pc_expire <= e_date)
                       ) NO-LOCK ,
    EACH exc WHERE exc_curr = pc_curr
                 BREAK BY pc_part BY pc_list BY pc_start BY pc_expire:

/*         DISP pc_list pc_part pc_um pc_curr pc_start pc_expire pc_amt[1] exc_rate. */
    
     IF LAST-OF (pc_list) THEN DO: 
       ACCUMULATE pc_amt[1] * exc_rate (MIN BY pc_part) .
       ACCUMULATE pc_amt[1] * exc_rate (MAX BY pc_part).
       ACCUMULATE pc_amt[1] (COUNT BY pc_part).
     END. 
     
/*     IF LAST-OF (pc_part) THEN DO:  */
       DISP pc_list 
            pc_part 
            pc_um 
            pc_curr 
            pc_start 
/*             pc_expire */
            ACCUM MIN BY pc_part pc_amt[1] * exc_rate FORMAT ">>,>>9.99<<<<<"
            ACCUM MAX BY pc_part pc_amt[1] * exc_rate FORMAT ">>,>>9.99<<<<<"
            ACCUM COUNT BY pc_part pc_amt[1]
            pc_amt[1] FORMAT ">>,>>9.99<<<<<"
       WITH WIDTH 120 .
/*     END. */

END.
